//
//  RIDRecord.m
//  SimulacraDB
//
//  Created by Andre Cohen on 9/10/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "RIDRecord.h"
#import "RID.h"

@implementation RIDRecord

@synthesize value;

- (id)initWithData:(ByteArray *)data {
	[super init];
	[self setValueFromData:data];
	return self;
}

- (id)initWithValue:(NSObject *)data {
	[super init];
	[self setValue:(NSNumber *)data];
	return self;
}

- (void)setValueFromData:(ByteArray *)data {
	value = [RID createWithPage:[data getIntFromLocation:0] offset:[data getIntFromLocation:2]];
}

- (ByteArray *)toByteArray {
	ByteArray *data = [ByteArray createWithSize:4];
	[data setIntAtLocation:0 value:[value page]];
	[data setIntAtLocation:1 value:[value offset]];
	return data;
}

- (void)setValue:(NSObject *)object {
	value = [(RID *) object clone];
}

- (int)size {
	return 4;
}

- (NSString *)description {
	return [value description];
}

- (BOOL)lessThan:(id)anObject {
	if([value page] < [[(RIDRecord *)anObject value] page])
		return TRUE;
	return ([value page] == [[(RIDRecord *)anObject value] page] && [value offset] < [[(RIDRecord *)anObject value] offset]);
}
- (BOOL)greaterThan:(id)anObject {
	if([value page] > [[(RIDRecord *)anObject value] page])
		return TRUE;
	return ([value page] == [[(RIDRecord *)anObject value] page] && [value offset] > [[(RIDRecord *)anObject value] offset]);
}
- (BOOL)equalTo:(id)anObject {
	return ([value page] == [[(RIDRecord *)anObject value] page] && [value offset] == [[(RIDRecord *)anObject value] offset]);
}

@end
